package com.example.a2306_fx

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader

object BindingAdater {
    @JvmStatic
    @BindingAdapter("img_url")
    fun bindImage(imageView: ImageView,url:String?){
        if(url!=null){
            Glide.with(imageView.context).load(url).into(imageView)
        }
    }
    @BindingAdapter("banner_url")
    @JvmStatic
    fun bindBanner(banner: Banner,imgs:MutableList<String>?){
        if (imgs != null) {
            banner.setImages(imgs)
            banner.setImageLoader(object :ImageLoader(){
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    if (context != null) {
                        if (imageView != null) {
                            Glide.with(context).load(path).into(imageView)
                        }
                    }
                }
            })
            banner.start()
        }
    }
}